<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/22
  Time: 19:46
 注册页面
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"
         import="inspur.dao.UserDao,inspur.common.FiledCheck,inspur.entity.User" %>
<%@ include file="config.jsp" %>
<html>
<head>
    <title><%=webTitle%>
    </title>
    <meta name="Keywords" content="<%=keywords%>">
    <meta name="Description" content="<%=Description%>">
    <link rel="stylesheet" href="css/style.css">
    <script>
        var issuccess = false;
        if (issuccess) {
            alert("注册成功，3秒后跳转到登录界面");
            setTimeout(window.open("login.jsp"), 3000);
        }
    </script>
</head>
<body>
<div align="center">
    <%@include file="component/top.jsp"%><!---顶栏-->
    <%@include file="component/checkBox.jsp"%><!--搜索框-->
    <table>
        <tr>
            <td>
                <%
                    boolean isSuccess = false;
                    String userIdError = "";
                    String passWordError = "";
                    String userNameError = "";
                    String secondPassError = "";
                    String one_messageError = "";
                    //从表单里面获得用户名和密码的值
                    request.setCharacterEncoding("utf-8");
                    //String username=request.getParameter("UserId");
                    String userId = request.getParameter("userId");
                    String passWord = request.getParameter("passWord");
                    String secondPass = request.getParameter("secondPass");
                    String userName = request.getParameter("userName");
                    String one_message = request.getParameter("one_message");
                    if (userId == null) {
                        userId = "";
                    }
                    if (passWord == null) {
                        passWord = "";
                    }
                    if (secondPass == null) {
                        secondPass = "";
                    }
                    if (userName == null) {
                        userName = "";
                    }
                    if (one_message == null) {
                        one_message = "";
                    }

                    //非空的校验
                    if (FiledCheck.isBlack(userId)) {
                        userIdError="用户名不能为空";

                    } else if (FiledCheck.isBlack(passWord)) {
                        passWordError = "密码不能为空";

                    } else if (!passWord.equals(secondPass)) {
                        secondPassError="重复密码不一致";

                    } else if (FiledCheck.isBlack(one_message)) {
                        one_messageError = "验证码不能为空";

                    } else if (!one_message.equalsIgnoreCase((String) session.getAttribute("rand"))) {
                        one_messageError = "验证码错误";
                    } else {


                        //登录信息的校验
                        User user = new User();
                        user.setId(userId);
                        user.setUsername(userName);
                        user.setPassword(passWord);

                        UserDao userDao = new UserDao();
                        int num = userDao.reg(user);
                        if (num == 2) {
                            userNameError = "注册成功,2秒后跳转到登录界面";
                            isSuccess = true;
                        } else {
                            //用户名 或者密码错误
                            if (num == 0) {
                                userNameError = "用户已存在";
                            } else {
                                //用户名不存在 或者 错误
                                //request.setAttribute("usernameError", "用户名错误");
                                userIdError = "用户名不存在或者错误";

                            }
                            //请求转发
                            //request.getRequestDispatcher("/login.jsp").forward(request, response);
                            System.out.println("hello ");

                        }

                    }


                %>
                <script>
                    issuccess =<%=isSuccess%>;
                    if (issuccess) {
                        setTimeout("self.location='login.jsp';", 2000);


                    }
                </script>
                <form method='post' action=''>
                    <p align="left">

                        用户账号：<input type=text class="box2" name="userId" value='<%=userId%>'><%=userIdError%><br><br>
                        账号密码：<input type=password class="box2" name="passWord" value='<%=passWord%>'><%=passWordError%>
                        <br><br>
                        重复密码：<input type=password class="box2" name="secondPass"
                                    value='<%=secondPass%>'><%=secondPassError%><br><br>
                        账号昵称：<input type=text class="box2" name="userName" value='<%=userName%>'><%=userNameError%>
                        <br><br>
                        验证码&nbsp&nbsp&nbsp：<input type=text class="box2" name="one_message" value=''
                                                  placeholder="请输入验证码">
                        <image id="imagecheck" class="checkImage" src=""></image>
                        <%=one_messageError%>
                        <br><br>
                        <input type="submit" class="bt500x50" name='tj' value='确认无误，提交以上信息'>
                    </P>
                </form>
            </td>
        </tr>
    </table>
</div>
<%

%>
<%--更换验证码--%>
<script src="js/changeIC.js"></script>
</body>
</div>
</body>
</html>
